﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Se7en.Admin.Model;
using System.Web.UI.WebControls;

namespace Se7en.Admin.Common
{
    public class UserControlBase : UserControl
    {
        #region Properties

        public Modes Mode
        {
            get
            {
                if (ViewState[Keys.ViewState.Mode] == null)
                    ViewState[Keys.ViewState.Mode] = Modes.View;

                return (Modes)ViewState[Keys.ViewState.Mode];
            }

            set
            {
                ViewState[Keys.ViewState.Mode] = value;
            }
        }

        public AdminContext DBContext
        {
            get
            {
                return ((PageBase)this.Page).DBContext;
            }
        }

        protected AdminPageBase AdminPage
        {
            get
            {
                return this.Page as AdminPageBase;
            }
        }

        #endregion

        #region Methods

        public void ShowMsg(Label lbl, MessageType msgType)
        {
            ((PageBase)this.Page).ShowMsg(lbl, msgType);
        }

        public void ShowMsg(string message, Label lbl, MessageType msgType)
        {
            ((PageBase)this.Page).ShowMsg(message, lbl, msgType);
        }

        public void ValidateMaxLengthMultiline(TextBox txt)
        {
            ((AdminPageBase)this.Page).ValidateMaxLengthMultiline(txt);
        }


        #endregion

        #region Events

        public event EventHandler Cancel;
        public event EventHandler Success;
        public event EventHandler Fail;

        protected void OnSuccess(object sender, EventArgs e)
        {
            if (Success != null)
                Success(sender, e);
        }

        protected void OnFail(object sender, EventArgs e)
        {
            if (Fail != null)
                Fail(sender, e);
        }

        protected void OnCancel(object sender, EventArgs e)
        {
            if (Cancel != null)
                Cancel(sender, e);
        }

        #endregion
    }
}
